package com.bosssoft.cloud.wechat.infrastructure.bean.response;

import com.alibaba.fastjson.annotation.JSONField;
import com.bosssoft.cloud.wechat.infrastructure.enums.ReturnEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 接口返回对象
 *
 * @author wcy create on 2021/5/18 18:20 下午
 */
@Data
@NoArgsConstructor
public class R<T> {

    @JSONField(name = "state", ordinal = 1)
    private String state;
    @JSONField(name = "message", ordinal = 2)
    private String message;
    @JSONField(name = "data", ordinal = 3)
    private T data;

    public R(String state, String message) {
        this.state = state;
        this.message = message;
    }

    public R(String state, String message, T data) {
        this(state, message);
        this.data = data;
    }

    public R(ReturnEnum resultEnum) {
        this.state = resultEnum.getCode();
        this.message = resultEnum.getMessage();
    }

    public R(ReturnEnum resultEnum, T data) {
        this.state = resultEnum.getCode();
        this.message = resultEnum.getMessage();
        this.data = data;
    }
}